import services from '@/services/demo';
import { PageContainer } from '@ant-design/pro-components';
import { Access, useAccess } from '@umijs/max';
import { Button, message } from 'antd';
const { getAdmin } = services.AdminController;

const handleAdmin = async () => {
  const hide = message.loading('正在请求');
  try {
    let msg = await getAdmin();
    hide();
    message.success('请求成功:' + msg);
    return true;
  } catch (error) {
    hide();
    message.error('请求失败请重试！');
    return false;
  }
};

const AccessPage: React.FC = () => {
  const access = useAccess();
  return (
    <PageContainer
      ghost
      header={{
        title: '权限示例',
      }}
    >
      <Access accessible={access.canSeeAdmin}>
        <Button
          onClick={() => {
            handleAdmin();
          }}
        >
          只有 Admin 可以看到这个按钮
        </Button>
      </Access>
    </PageContainer>
  );
};

export default AccessPage;
